package dao.impl;

import java.sql.SQLException;

import org.apache.commons.dbutils.handlers.BeanHandler;

import bean.Apply;
import dao.ApplyDao;

public class ApplyDaoImpl extends BaseDao implements ApplyDao{

	@Override
	public Integer selectApplybyid(Integer id) {
		try {
			Object query2=query.query("select * from apply where applyid=?",id,new BeanHandler<Apply>(Apply.class));
			return Integer.parseInt(query2.toString());
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return -1;
	}
	//Apply
	@Override
	public Integer deleteApplybyid(Integer id) {
		try {
			return query.update("delete from apply where applyid=?",id);
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return -1;
	}

	@Override
	public Integer updateApply(Apply info) {
		String sql="update apply set baomingid=?,foodid=?,objectid=?,applytypeid=?,"
				+ "applytime=?,applyreason=?,remark=?,applytype=?,time=?,type=? where applyid=?";
		try {
			return query.update(sql,info.getBaomingid(),info.getFoodid(),info.getObjectid(),
					info.getApplytypeid(),info.getApplytime(),info.getApplyreason(),info.getRemark(),
					info.getApplytype(),info.getTime(),info.getType());
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return -1;
	}

	@Override
	public Integer addApply(Apply info) {
		String sql="insert into apply(baomingid,foodid,objectid,applytypeid,applytime,applyreason,remark,"
				+ "applytype,time,type) VALUES(?,?,?,?,?,?,?,?,?,?)";
		try {
			return query.update(sql,info.getBaomingid(),info.getFoodid(),info.getObjectid(),
					info.getApplytypeid(),info.getApplytime(),info.getApplyreason(),info.getRemark(),
					info.getApplytype(),info.getTime(),info.getType());
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return -1;
	}
	@Override
	public Integer addApply2(Apply info) {
		String sql="INSERT INTO apply(baomingid,applytypeid,applytime,applyreason,remark,applytype,type) \r\n" + 
				"VALUE(1,?,NOW(),?,?,?,1)";
		try {
			return query.update(sql,info.getApplytypeid(),info.getApplyreason(),
					info.getRemark(),info.getApplytype());
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return -1;
	}

}
